﻿@{
    ViewBag.Title = "UserList";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <style>
        .txtright
        {
            text-align: right;
            width: 90px;
        }
        .contHeight
        {
            height: 155px;
            overflow-y: scroll;
        }
        .p2
        {
            display: none;
        }
    </style>
    <script type="text/javascript">
        $(function () {
            var id = $.getUrlParam("id");
            if (!($.getUrlParam("dbType") == 1 || $.getUrlParam("dbType") == 2 || $.getUrlParam("dbType") == 4 || $.getUrlParam("dbType") == 8)) {
                $(".ddlCallBackType option[value=1]").remove();
                GetCallBackType(2);
            }
            if (id) {
                var parent = window.dialogArguments; //获取父页面参数  
                $(".ddlCallBackType").val($.trim(parent.retCBData[id].CallBackType));
                $(".txtParaCallBack").val(parent.retCBData[id].CallBackName);
                $(".txtHttpCallBack").val(parent.retCBData[id].CallBackName);
                var paras = parent.retCBData[id].Paras; //ParaValues
                if ($.trim(parent.retCBData[id].CallBackType) == 2 && paras) {
                    GetCallBackType(2);
                    var paraArr = paras.split("&");
                    var paraValuesArr = parent.retCBData[id].ParaValues.split("&");
                    $(".txtPara").val(paraArr[0]);
                    $(".txtParaValue").val(paraValuesArr[0]);
                    for (var i = 0; i < paraArr.length; i++) {
                        AddPara(paraArr[i], paraValuesArr[i]);
                    }
                }
            }
        });
        var pNum = 0;
        function AddPara(k, v) {
            $(".paras").append("<div class='ph" + pNum + "'>参数名 <input type='text' value='" + k + "' class='txtPara' style='width: 120px;' /> 参数值 <input type='text' value='" + v + "' class='txtParaValue' style='width: 140px;' /> <input type='button' value='删除' onclick='DelPara(" + pNum + ");' class='button' /></div>");
            pNum++;
        }
        function DelPara(v) {
            $(".ph" + v).remove();
        }
        function GetCallBackType(v) {
            if (v == 1) {
                $(".p1").show();
                $(".p2").hide();
            } else {
                $(".p2").show();
                $(".p1").hide();
            }
        }
        function save() {
            var cbTy = $(".ddlCallBackType").val();
            var cbpName = $.trim($(".txtParaCallBack").val());
            var cbhName = $.trim($(".txtHttpCallBack").val());
            var cbName;
            if (cbTy == "1") {
                if (cbpName == "") {
                    alert("存储过程名称不能为空！");
                    return;
                }
                cbName = cbpName;
            }
            else {
                if (cbhName == "") {
                    alert("HTTP地址不能为空！");
                    return;
                }
                cbName = cbhName;
            }
            var paras = getArrValue(".txtPara", "&");
            var paraValues = getArrValue(".txtParaValue", "&");
            var rtvalue = {};
            rtvalue["GUID"] = $.getUrlParam("id");
            rtvalue["CallBackType"] = cbTy;
            rtvalue["CallBackName"] = cbName;
            rtvalue["Paras"] = paras;
            rtvalue["ParaValues"] = paraValues;
            returnParent(rtvalue);
        }
    </script>
}
<div style="margin: 5px;">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/edit.png" />
            </td>
            <td width="220">
                回调配置
            </td>
            <td align="right">
                <input type="button" value="确定" onclick="save();" class="button" />
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td valign="top">
                <div class="contHeight">
                    <table class="sql table_bg" width="100%">
                        <tr>
                            <td class="txtright">
                                回调类型：
                            </td>
                            <td>
                                <select style="width: 150px;" class="ddlCallBackType" onchange="GetCallBackType(this.value)">
                                    <option value="1">存储过程</option>
                                    <option value="2">HTTP回调</option>
                                </select>
                            </td>
                        </tr>
                        <tr class="p1">
                            <td class="txtright">
                                存储过程名称：
                            </td>
                            <td>
                                <input type="text" class="txtParaCallBack" style="width: 350px;" />
                            </td>
                        </tr>
                        <tr class="p2">
                            <td class="txtright">
                                HTTP地址：
                            </td>
                            <td>
                                <input type="text" class="txtHttpCallBack" style="width: 350px;" />
                            </td>
                        </tr>
                        <tr class="p2">
                            <td class="txtright" valign="top">
                                参数配置：
                            </td>
                            <td align="right" class="paras">
                                 
                                <input type="button" value="添加" onclick="AddPara('','');" class="button" />
                            </td>
                        </tr>
                    </table>
                </div>
            </td>
        </tr>
    </table>
</div>
